<template>
	<view class="wrap">
		<u-swiper :height="270" :list="imgList" :title="false" @click="imgListClick"></u-swiper>
		<view v-for="(item, index) in menuList" :key="index">
			<view class="workbench-title">{{item.label}}</view>
			<view class="toolbar">
				<u-grid class="grid" :col="4" :border="false">
					<u-grid-item :index="idx" @click="navTo(m.path)"  v-for="(m, idx) in item.menuList" :key="idx">
						<view v-if="m.path==='/pages/flowableplus/work/todo/index'" style="position: relative;">
							<view class="home-icon" :style="m.style">
								<i :class="m.source"></i>
							</view>
							<view class="grid-text">{{m.name}}</view>
							<u-badge v-if="todoCount>0" :count="todoCount" :offset="[-10, 0]"></u-badge>
						</view>
						<view v-else>
							<view class="home-icon" :style="m.style">
								<i :class="m.source"></i>
							</view>
							<view class="grid-text">{{m.name}}</view>
						</view>
						
					</u-grid-item>
					<u-grid-item  @click="navTo('/pages/sys/workbench/install')" v-if="item.key=='-1'">
						<view class="home-icon icon-color13">
							<i class="fjutfont fjut-tianjiachangyong" style="color:#90949d;"></i>
						</view>
						<view class="grid-text">添加常用</view>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
		<u-divider>已经到底了</u-divider>
	</view>
	
</template>
<script>
	 import HeadNavBar from '@/components/headnavbar/index';
	 import {validatenull} from '@/common/validate.js'
/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
export default {
	components: {
	  HeadNavBar
	},
	data() {
		return {
			show: false,
			head: '/static/aidex/images/head.png',
			imgList: [],
			todoCount: 0,
			menuList: []
		};
	},
	onLoad() {
		this.getRotationList();
		this.initMenu();
	},
	methods: {
		initMenu(){
			let this_=this;
			this.$u.api.menu.getRoute({}).then(res => {
				this.menuList=res.data;
				//如果有待办链接，则去取待办数量
				res.data.forEach((item) => {
					item.menuList.forEach((subItem) => {
						if(subItem.path==='/pages/flowableplus/work/todo/index'){
							this.$u.api.wflow.process.todoCount({}).then(res => {
								if(res.code==200){
									this_.todoCount = res.data;
								}
							});
							
						}
					})
				})
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		imgListClick(index) {
			if(!validatenull(this.imgList[index].toLink)){
				 let url=encodeURIComponent(this.imgList[index].toLink);
				uni.navigateTo({
					url:'/pages/common/webview?url='+url
				})
			}
		},
		itemClick(index) {
			console.log(index);
		},
		getRotationList(){
			this.$u.api.rotation.list({}).then(res => {
				if(res.code==200){
					res.data.forEach((item) => {
						let json={}
						json['image']=item.url
						json['title']= item.title
						json['toLink']= item.toLink
						this.imgList.push(json);
					})
				}
			});
			
		},
	}
};
</script>
<style lang="scss">
@import 'index.scss';
.banner-box{
	padding: 0 2%;
	width: 96%;
	height: 170rpx;
	margin: 30rpx 0 30rpx;
}
.u-swiper-wrap{
	padding:0 10px;
}

.banner-pic{
	width: 47%;
	float: left;
	display: inline-block;
	margin: 0 1.5%;
}
.banner-pic image{
	width: 100%;
	height: 170rpx;
	border-radius: 12rpx;
	box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
}

.u-mode-light-info{
    background-color: #ffffff;
    color: #666666;
    border: 1px solid #e9ecf6;
	font-size: 12px;
	padding: 2px 8px;
	position: relative;
	top:-3px;
}
.workbench-title{
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
	padding: 15px 30rpx;
}
 .home-icon i.icon-tongzhi{
	// font-size: 22px;
	position: relative;
	margin:0 auto;
 }
</style>
